<template>
    <div id="task-issue-selector">
        <div 
            class="task-issue-atd-selector" 
            v-for="(item, index) in list" 
            :key="`issue-task ${index}`"
            :style="sColor(item)"
            @click="updateArr(item)" >
            {{ getName(item) }}
        </div>
    </div>
</template>

<script>
export default {
    data() {
        return {
            source: []
        }
    },
    props: {
        list: {
            type: Array,
            default: () => {
                return []
            }
        },
        level: {
            type: Number,
            default: -1
        }
    },
    watch: {
        source(v) {
            this.$emit("on-change", {
                level: this.level,
                value: v
            })
        }
    },
    methods: {
        updateArr(v) {
            let name = this.getName(v);
            let index = this.source.indexOf(name);
            if (index > -1) {
                this.source.splice(index, 1);
            } else {
                this.source.push(name);
            }
        },
        sColor(v) {
            let name = this.getName(v)
            if (this.source.indexOf(name) > -1) {
                return {
                    background: "rgb(45, 140, 240)",
                    color: "white"
                }
            }
        },
        getName(v) {
            switch(this.level) {
                case 1: return v.deptName
                case 2: return v.groupName
                case 3: return v.name
            }
        }
    }
}
</script>

<style lang="scss">
@import "@task/scss/issue-task-selector.scss";
</style>